<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>cookie操作登陆页面</title>
</head>
<body>
	<div id="box1">
		用户名：<input type="text" name="" id="username"><br>
		密码：<input type="password" name="" id="userpass"><br>
		<button id="dl">登陆</button>
	</div>
	
	<script>
		
		//登陆
		if(document.cookie!=''){
			window.location.href ='denglu.html';
		}else{

			dl.onclick = function(){

				//设置有效时间
				var expReadyDay = 1;
				var date = new Date();

				//当前时间加上有效期换成毫秒
				date.setTime(date.getTime()+expReadyDay*24*60*60*1000);

				//用户名密码
				if(username.value!=''&&userpass.value!=''){
					document.cookie = 'ursename=' + username.value + ';expires=' + date.toUTCString();
					document.cookie = 'password=' + userpass.value + ';expires=' + date.toUTCString();

					
					username.value = '';
					userpass.value = '';
					window.location.href ='denglu.html';

				}else{
					alert('用户名或密码不能为空');
				}
				console.log(document.cookie);
			}
		}

		
	</script>
</body>
</html>